﻿using System;
using System.Text;

namespace ChatClient
{
	internal class Protocol
	{
		public static byte[] AddLength(byte[] command)
		{
			var result = new byte[command.Length + sizeof (UInt32)];
			Array.Copy(command, 0, result, sizeof (UInt32), command.Length);
			byte[] lengthArray = BitConverter.GetBytes((UInt32) command.Length);
			Array.Copy(lengthArray, 0, result, 0, lengthArray.Length);
			return result;
		}

		public static byte[] Hello(String name, String ver)
		{
			return AddLength(Encoding.ASCII.GetBytes("hello" + name + ver));
		}

		public static byte[] Bye()
		{
			return AddLength(Encoding.ASCII.GetBytes("bye"));
		}

		public static byte[] SendMessage(String message)
		{
			return AddLength(Encoding.ASCII.GetBytes("send" + message));
		}

		public static byte[] GetN(String n)
		{
			return AddLength(Encoding.ASCII.GetBytes("get" + n));
		}

		public static byte[] GetClients()
		{
			return AddLength(Encoding.ASCII.GetBytes("list"));
		}
	}
}